// Copyright (c) 2020 Presto Labs Pte. Ltd.
// Author: leon

#pragma once

#include <map>
#include <memory>
#include <regex>
#include <string>
#include <vector>

// internal
#include "coin2/exchange/base/feed/processor.h"
#include "coin2/exchange/base/market/enums.h"
#include "coin2/exchange/di/constant.h"

namespace coin2::exchange::bitflyer_futures::feed_v1 {
namespace impl {
using namespace coin2::exchange::base::symbology;
class BitflyerFuturesFeedProcessor : public base::feed::FeedParsingProcessor {
 public:
  explicit BitflyerFuturesFeedProcessor(
      const std::string& system_name,
      const coin2::exchange::di::ConstantInjection& ci,
      const feed::RawParserConfig& config)
      : FeedParsingProcessor(
            system_name,
            MarketExchangeApi{MarketType::Futures, ExchangeType::Bitflyer, "v1"},
            ci,
            config,
            "cc/coin2/exchange/bitflyer_futures/feed_v1/schema.json") {}
  void OnTopicRecord(const base::executor::TopicRecordPacket& packet) override;
};
struct BitflyerFuturesChannel {
  std::string channel;
  std::string native_symbol;

  static BitflyerFuturesChannel Parse(const std::string& channel) {
    /*
    "lightning_board_XXX"
    "lightning_board_snapshot_XXX"
    "lightning_executions_XXX"
    */
    if (channel.find("lightning_board_snapshot_") == 0) {
      return BitflyerFuturesChannel{"lightning_board_snapshot", channel.substr(25)};
    } else if (channel.find("lightning_board_") == 0) {
      return BitflyerFuturesChannel{"lightning_board", channel.substr(16)};
    } else if (channel.find("lightning_executions_") == 0) {
      return BitflyerFuturesChannel{"lightning_executions", channel.substr(21)};
    } else {
      THROW() << "unknown channel: " << channel;
      return BitflyerFuturesChannel{};
    }
  }
};
};  // namespace impl
using impl::BitflyerFuturesChannel;
using impl::BitflyerFuturesFeedProcessor;
}  // namespace coin2::exchange::bitflyer_futures::feed_v1
